package com.wash.shoes.controller.pc;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.wash.shoes.entity.UserBlacklistPo;
import com.wash.shoes.service.UserBlackListService;
import com.wash.shoes.util.RegularValidatorUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;

/**
 * 用户黑名单管理Controller
 *
 * @author wangxy
 * @date 2024-12-26
 */
@Api(tags = {"PC-用户黑名单"})
@RestController
@RequestMapping({"/userBlackList", "/dev-api/userBlackList"})
public class OsUserBlacklistController extends BaseController {
    @Autowired
    private UserBlackListService userBlackListService;

    @ApiOperation("查询用户黑名单列表")
    @PostMapping("/queryUserBlackList")
    public R<Page<UserBlacklistPo>> pageList(@RequestBody UserBlacklistPo osUserBlacklistPo) {
        Page<UserBlacklistPo> page = userBlackListService.pageList(osUserBlacklistPo);
        return R.ok(page);
    }

    @ApiOperation("用户黑名单新增修改,有id为修改没有为新增")
    @PostMapping("/saveUpdateUserBlackList")
    public R<Boolean> add(@RequestBody UserBlacklistPo osUserBlacklistPo) {
        //校验手机电话号码
        if (!RegularValidatorUtil.isValidChinaPhoneNumber(osUserBlacklistPo.getPhoneNumber())) {
            return R.fail("用户黑名单手机不合法");
        }
        if (ObjectUtil.isEmpty(osUserBlacklistPo.getId())) {
            boolean saveFlag = userBlackListService.save(osUserBlacklistPo);
            return R.ok(saveFlag);
        } else {
            boolean updateFlag = userBlackListService.updateById(osUserBlacklistPo);
            return R.ok(updateFlag);
        }
    }

    @ApiOperation("从列表中移除用户黑名单")
    @GetMapping("/deleteByUserBlackListId")
    public R<Boolean> deleteByStatus(String id) {
        boolean flag = userBlackListService.removeById(id);
        return R.ok(flag);
    }
}
